//package com.springvision.core.tcpclient;
//
//
//import com.fnic.functionSwitch.web.core.task.callback.TaskFeedback;
//import com.fnic.functionSwitch.web.core.task.model.FeedBackInfo;
//import com.fnic.functionSwitch.web.core.task.model.TaskSetWithChannleMap;
//import com.fnic.functionSwitch.web.core.task.callback.CallbackEvent;
//import com.fnic.functionSwitch.web.util.GsonUtil;
//import io.netty.channel.*;
//import io.netty.handler.timeout.IdleStateEvent;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//@Component
//@ChannelHandler.Sharable
//public class LogicClientHandler extends ChannelInboundHandlerAdapter {
//
//    Logger logger = LoggerFactory.getLogger(LogicClientHandler.class);
//
//    @Autowired
//    private CallbackEvent callbackEvent;
//
//    @Override
//    public void channelActive(ChannelHandlerContext ctx) throws Exception {
//        ctx.channel().closeFuture().addListener(new ChannelFutureListener() {
//            @Override
//            public void operationComplete(ChannelFuture future) throws Exception {
//                callbackEvent.noticeTaskFinish(future.channel().id().asLongText());
//            }
//        });
//    }
//
//    @Override
//    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//        String channelId = ctx.channel().id().asLongText();
//        SmartCarProtocol response = (SmartCarProtocol) msg;
//        String body = new String(response.getContent());
//        body = body.replace("\0","");
//        TaskFeedback taskFeedBack = GsonUtil.SIMPLEGSON.fromJson(body, TaskFeedback.class);
//        taskFeedBack.decide();
//        if (!TaskSetWithChannleMap.existTaskBase(channelId, taskFeedBack.getTaskid())) {
//            return;
//        }
//        TaskSetWithChannleMap.removeTaskBase(channelId, taskFeedBack.getTaskid());
//        boolean complete = TaskSetWithChannleMap.taskIsFinished(channelId);
//        FeedBackInfo feedBackInfo = new FeedBackInfo(channelId, taskFeedBack, complete);
//        callbackEvent.notice(feedBackInfo);
//        if (complete) {
//            ctx.close();
//        }
//    }
//
//    @Override
//    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
//        if (evt instanceof IdleStateEvent) {
////            IdleStateEvent e = (IdleStateEvent) evt;
////            switch (e.state()) {
////                case ALL_IDLE:
////                case READER_IDLE:
////                case WRITER_IDLE:
////                    ctx.close();
////                    break;
////            }
//            ctx.close();
//        }
//    }
//}
